<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>KD组织资产左侧菜单树</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<!--  树结构  -->
<script type="text/javascript" src="${_resources}js/jquery.ztree.core.js"></script>
<link rel="stylesheet" href="${_resources}css/zTreeStyle.css" type="text/css">


<link href='${_resources}css/style.css' type='text/css' rel='stylesheet' />

<script type="text/javascript">
 	var	parentId;
	var ztree;
	var setting = {	
			view: {
				fontCss : {border:"0",background:"none","text-decoration":"none"},
                showIcon: false,
    			showLine: true,
    			selectedMulti: false,
    			dblClickExpand: false	
    		},
		data: {
			simpleData: {
				enable: true,
				idKey: "menuId",
				pIdKey: "parentId"
			}
		},
		callback: {
			onNodeCreated: this.onNodeCreated,				
			onClick:onClick			
		}
	};
	
	var zNodes = eval('(${menuList})');
	$(document).ready(function(){
		ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		if("zuzhizichan" == "${needExpandNodeId}"){
			var div = document.getElementById("templatelist");
			div.src = "${_baseUrl}/organizeassets/showOrganizeassetsIndex?random="+Math.random();
			var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			treeObj.expandAll(true); 
		}else{
			ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
			ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//触发函数
			var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			treeObj.expandAll(true); 
		}
		
		$("#menuName").click(function(){
			if(this.innerText.indexOf("组织资产") != -1){
				ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
				var div = document.getElementById("templatelist");
				div.src ="${_baseUrl}/organizeassets/showOrganizeassetsIndex?random="+Math.random();				
			}			
		});
	});
	
	function onClick(e,treeId, treeNode) {
		parentId=treeNode.menuId;
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.expandNode(treeNode);
        var div = document.getElementById("templatelist");
        div.src ="${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&random="+Math.random();
	}
	
	function refreshTree(){
		 var menuId="${menuInfo.menuId}"; 
		 $.ajax({
				url : "${_baseUrl}/jurisdiction/menuTreeList?menuId="+menuId,
				type : "post",
				dataType : "json",
				async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
				success : function(json) {
					if(json.code=="1"){
						zNodes= eval(json.data);
						ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
						ztree.selectNode(ztree.getNodeByParam("menuId",parentId,null));//选中指定节点
						ztree.expandNode(ztree.getNodeByParam("menuId",parentId,null));//展开指定节点	
						$("#menuName").click(function(){
							if(this.innerText.indexOf("组织资产") != -1){
								ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
								ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
								var div = document.getElementById("templatelist");
								div.src ="${_baseUrl}/organizeassets/showOrganizeassetsIndex?random="+Math.random();				
							}			
						});
					}	
				},
				error:function(data){
					layer.msg("系统错误,请联系管理员");
				}
			});
	}
</script>
<style type="text/css">
.btn { width:20px;display:inline-block; position:absolute; left:251px; z-index:999; }
.btn div { position:absolute; top:39%;width:20px;left:1px; vertical-align:center;}
.ztree li a{padding: 0px 3px 0px 0;}
</style>
</head>
<body>

<div class="main">
    <div id="main-left" class="zTreeDemoBackground main_left" style="overflow: auto;">
        <div class="left_menu_tree" style="margin-left:0px;">
            <ul id="treeDemo" class="ztree" style="overflow: auto;"></ul>
        </div>
	
    </div>
    <!-- 图标按钮开始  -->
    <div id="btn" class="btn">
		<div id="cont_a" class="close" onclick="slipHidden();initWidth()"></div>
		<div id="cont_b" class="open" onclick="slipShow();initWidth()" style="display:none;"></div>
	</div>
    <!-- 图标按钮结束 -->
    <div id="main-right" class="main_right">
    	
        <iframe id="templatelist" width='100%' height='100%' src="" frameborder="0" scrolling="auto" name="aaaaaaa">
        </iframe>
    </div>
</div>
</body>
<script type="text/javascript">
var  resizeTimer = null;
window.onload = function(){
	initWidth();
	initHeight();
}
window.onresize = function(){
    if(resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout("initHeight();initWidth();",100);
 }
function initHeight(){
	var topH = 0; 
	if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
		initheight = document.documentElement.clientHeight-topH;
	}
	if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
		initheight = document.documentElement.clientHeight-topH;
	}
	if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
		initheight = document.body.clientHeight-topH;
	}
	if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
		initheight = document.documentElement.clientHeight-topH;
	}
	if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
		initheight = document.documentElement.clientHeight-topH;
	}
	$("#btn").css( "height",initheight-5);
    $("#btn").css( {"position":"relative"});
}
function initWidth(){
	var oMaBox = document.getElementById("main-left");
	var topW = oMaBox.getBoundingClientRect().width; 
	
	if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
		topW = oMaBox.clientWidth;
		initwidth = document.documentElement.clientWidth-topW;
	}
	if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
		initwidth = document.documentElement.clientWidth-topW;
	}
	if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
		initwidth = document.body.clientWidth-topW;
	}
	if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
		initwidth = document.documentElement.clientWidth-topW;
	}
	if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
		initwidth = document.documentElement.clientWidth-topW;
	}
	$("#btn").css( {"position":"relative","left":topW});
	$("#main-right").css( {"width":initwidth-25,"position":"absolute","left":topW+20});
}
function slipHidden(){
	var oTop = document.getElementById("cont_a");
	var oDown = document.getElementById("cont_b");
	var oBox = document.getElementById("main-left");
	var oBtn = document.getElementById("btn");
	oTop.style.display = "none";
	oDown.style.display = "block";
	oBox.style.display = "none";
	
}
function slipShow(){
	var oTop = document.getElementById("cont_a");
	var oDown = document.getElementById("cont_b");
	var oBox = document.getElementById("main-left");
	var oBtn = document.getElementById("btn");
	oTop.style.display = "block";
	oDown.style.display = "none";
	oBox.style.display = "block";
	
}
</script>

</html>